﻿namespace _3
{
    class FindPrime
    {
        public int GetNum()
        {
            string s = "";
            int n = 0;
            Console.Write("Please enter the number:");
            s = Console.ReadLine();
            n = int.Parse(s);
            return n;
        }

        public int[] GetPrime(int n)
        {
            int[] b = new int[n + 1];
            for (int i = 0; i <= n; i++)
                b[i] = i;
            int p = 1;
            int P;
            do
            {
                P = p * p;
                if (b[p] >= 2)
                {
                    for (int j = 2; j * p <= n; j++)
                    {
                        b[j * p] = 1;
                    }
                    p++;
                }
                else
                    p++;
            } while (P <= n);
            int[] a = new int[n];
            int num = 0;
            for (int i = 0; i <= n; i++)
            {
                if (b[i] >= 2)
                {
                    a[num] = b[i];
                    num++;
                }
                else
                    continue;
            }
            return a;
        }

        public void WritePrime(int[] a)
        {
            int len = a.GetLength(0);
            for (int i = 0; i < len; i++)
            {
                if (a[i] != 0)
                {
                    Console.Write(a[i]);
                    Console.Write(" ");
                }
            }
        }
    }
    internal class Program
    {
        static void Main(string[] args)
        {
            FindPrime obj = new FindPrime();
            int num = 100;
            int[] arr = obj.GetPrime(num);
            obj.WritePrime(arr);
        }
    }
}
